# 使用队列进行进程间的通信
import os
from multiprocessing import Queue, Process
from time import sleep


def write(q):
    print("开始写进程--%s" % (os.getpid()))
    for char in ['A', 'B', 'C', 'D']:
        q.put(char)
        print(q.qsize())
        sleep(1)
        print(q.qsize())
    print("结束写进程--%s" % (os.getpid()))


def read(q):
    print('开始读进程--%s' % (os.getpid()))
    while True:
        value = q.get(True)
        print('value=' + value)
    print("结束读进程--%s" % (os.getpid()))


if __name__ == '__main__':
    print('父进程开始')
    q = Queue()
    pw = Process(target=write, args=(q,))
    pr = Process(target=read, args=(q,))
    pw.start()
    pr.start()
    pw.join()
    pr.terminate()
    print('父进程结束')
